

$(function(){
    $("#yzmBtn").bind("click", function(){
        getYzm();
    });
    $("#submit").bind("click", function(){
        submitPost();
    });

});


function getYzm() {

    var resendFlag = $('#yzmBtn').attr('resendFlag');
    var webName = $("#webName").val();
    if (webName == ''){
    	alert('请输入用户名');

        return false;
    }

    if (resendFlag == '1' && webName) {

    	 var url = $('#ctx').val()+'/getyzm?catch='+Math.random();
    	 var  param= {"webName":$('#webName').val()};

            $('#yzmBtn').attr('resendFlag', '0');
            $('#yzmBtn').css('color', 'ccc');
            $('#yzmBtn').css('cursor', 'default');
            $('#yzmBtn').html('60秒后重发');
            timeDownCnt = 60;
            timeDown();

    	Onluy.ajax.getSimpData(url, param, function(data) {
            //{"msg":"用户名或密码错误！","msgtype":0,"success":false,"total":0}
            alert(data.msg);
            if (data.success  ==false) {
                resetYzmBtn();
            }else{
                $('#BizId').html(data.msg);
			}
        }, function(data) {
            alert('获取验证码失败');
            resetYzmBtn();
        });




    }
}
function  resetYzmBtn() {
    $('#yzmBtn').attr('resendFlag', '1');
    $('#yzmBtn').css('color', '#555');
    $('#yzmBtn').css('cursor', 'pointer');
    $('#yzmBtn').html('获取验证码');
}

var timeDownCnt = 60;
var timeFuncId = -1;
function timeDown() {
    var resendFlag = $('#yzmBtn').attr('resendFlag');
    if (timeDownCnt <= 0) {
        timeDownCnt = 60;
        resetYzmBtn();
        clearTimeout(timeFuncId);
    } else  if (resendFlag == '0') {
            timeDownCnt--;
            var btnStr = timeDownCnt + '秒后重发';
            $('#yzmBtn').html(btnStr);
            timeFuncId = setTimeout('timeDown()', 1000);
    } else {
            if (timeFuncId != -1) {
                clearTimeout(timeFuncId);
            }
            timeDownCnt = 60;
            resetYzmBtn();
    }
}




function submitPost() {
    var webName = $("#webName").val();
    var webPasswd = $("#webPasswd").val();
    var yzm = $("#yzm").val();
    if (webName == '') {
        alert('请输入用户名');
        return false;
    }
    if (webPasswd == '') {
        alert('请输入密码');
        return false;
    }
    if (yzm == '') {
        alert('请输入验证码');
        return false;
    }

    var url = $('#ctx').val() + '/checkin?catch=' + Math.random();
    var param = {"webName": webName, "webPasswd": webPasswd, "yzm": yzm};

    Onluy.ajax.getSimpData(url, param, function (data) {
        //{"msg":"用户名或密码错误！","msgtype":0,"success":false,"total":0}
        if (data.success == true) {
            window.location.href=$('#ctx').val() +"/sysmgr/";
        } else {
            alert(data.msg);
        }
    }, function (data) {
        alert('=登陆失败='+'<br/>'+data);
    });

}